vicfg: Include mincopies configuration
authorJoey Hess <joeyh@joeyh.name>
Thu, 15 Sep 2022 19:11:59 +0000 (15:11 -0400)
committerJoey Hess <joeyh@joeyh.name>
Thu, 15 Sep 2022 19:11:59 +0000 (15:11 -0400)
Sponsored-by: k0ld on Patreon
CHANGELOG
Command/Vicfg.hs

index be72e2089ec4c18fb2a8a02930faa132dadf2712..a2e4af40acb2b9163e1b18dfca8a2320da3d67b1 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -13,6 +13,7 @@ git-annex (10.20220823) UNRELEASED; urgency=medium
   * Fix a reversion that made dead keys not be skipped when operating on
     all keys via --all or in a bare repo.
     (Introduced in version 8.20200720)
+  * vicfg: Include mincopies configuration.
 
  -- Joey Hess <id@joeyh.name>  Mon, 29 Aug 2022 15:03:04 -0400
 
index 3d2d2863911d9684d4ee1f9b39e1a4a5a36c3b3a..599d067fd93d02a53e2af441ee4c82dfb86de30d 100644 (file)
@@ -1,6 +1,6 @@
 {- git-annex command
  -
- - Copyright 2012-2017 Joey Hess <id@joeyh.name>
+ - Copyright 2012-2022 Joey Hess <id@joeyh.name>
  -
  - Licensed under the GNU AGPL version 3 or higher.
  -}
@@ -75,6 +75,7 @@ data Cfg = Cfg
        , cfgScheduleMap :: M.Map UUID [ScheduledActivity]
        , cfgGlobalConfigs :: M.Map ConfigKey ConfigValue
        , cfgNumCopies :: Maybe NumCopies
+       , cfgMinCopies :: Maybe MinCopies
        }
 
 getCfg :: Annex Cfg
@@ -87,6 +88,7 @@ getCfg = Cfg
        <*> scheduleMap
        <*> loadGlobalConfig
        <*> getGlobalNumCopies
+       <*> getGlobalMinCopies
 
 setCfg :: Cfg -> Cfg -> Annex ()
 setCfg curcfg newcfg = do
@@ -99,6 +101,7 @@ setCfg curcfg newcfg = do
        mapM_ (uncurry scheduleSet) $ M.toList $ cfgScheduleMap diff
        mapM_ (uncurry setGlobalConfig) $ M.toList $ cfgGlobalConfigs diff
        maybe noop setGlobalNumCopies $ cfgNumCopies diff
+       maybe noop setGlobalMinCopies $ cfgMinCopies diff
 
 {- Default config has all the keys from the input config, but with their
  - default values. -}
@@ -112,6 +115,7 @@ defCfg curcfg = Cfg
        , cfgScheduleMap = mapdef $ cfgScheduleMap curcfg
        , cfgGlobalConfigs = mapdef $ cfgGlobalConfigs curcfg
        , cfgNumCopies = Nothing
+       , cfgMinCopies = Nothing
        }
   where
        mapdef :: forall k v. Default v => M.Map k v -> M.Map k v
@@ -127,6 +131,7 @@ diffCfg curcfg newcfg = Cfg
        , cfgScheduleMap = diff cfgScheduleMap
        , cfgGlobalConfigs = diff cfgGlobalConfigs
        , cfgNumCopies = cfgNumCopies newcfg
+       , cfgMinCopies = cfgMinCopies newcfg
        }
   where
        diff f = M.differenceWith (\x y -> if x == y then Nothing else Just x)
@@ -236,6 +241,7 @@ genCfg cfg descs = unlines $ intercalate [""]
        numcopies =
                [ com "Numcopies configuration"
                , line' "numcopies" (show . fromNumCopies <$> cfgNumCopies cfg)
+               , line' "mincopies" (show . fromMinCopies <$> cfgMinCopies cfg)
                ]
        
 settings :: Ord v => Cfg -> UUIDDescMap -> (Cfg -> M.Map UUID v) -> [String] -> ((v, UUID) -> [String]) -> (UUID -> [String]) -> [String]
@@ -316,6 +322,9 @@ parseCfg defcfg = go [] defcfg . lines
                | setting == "numcopies" = case readish val of
                        Nothing -> Left "parse error (expected an integer)"
                        Just n -> Right $ cfg { cfgNumCopies = Just (configuredNumCopies n) }
+               | setting == "mincopies" = case readish val of
+                       Nothing -> Left "parse error (expected an integer)"
+                       Just n -> Right $ cfg { cfgMinCopies = Just (configuredMinCopies n) }
                | otherwise = badval "setting" setting
          where
                u = toUUID f